﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TI_BAL;
namespace SecuritySystem
{
    public partial class LoginForm : Form
    {
        
        TIEntities dbContext;
        public LoginForm()
        {
            InitializeComponent();
            dbContext = new TIEntities();
        }

        private void btnLogIn_Click(object sender, EventArgs e)
        {
           string userName = textBoxUserName.Text;
           string password= textBoxPassword.Text;
           if (!string.IsNullOrWhiteSpace(userName))
           {
               if (userName.Trim().Length > 3)
               {
                   User user =(from u in dbContext.Users where u.UserName == userName && u.Password == password select u).FirstOrDefault();

                   if (user != null)
                   {
                       this.Hide();
                       SSAccountsParent tiAccountsParent = new SSAccountsParent();
                       tiAccountsParent.Show();
                   }
                   else
                   {
                       MessageBox.Show("Invalid User Name or Password.");
                   }
               }
               else
               {
                   MessageBox.Show("Please enter a valid name.");
               }
           }
           else
           {
               MessageBox.Show("Please enter a valid name.");
           }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void LoginForm_Load(object sender, EventArgs e)
        {
            this.Text = System.Configuration.ConfigurationSettings.AppSettings["SoftwareName"];
        }
    }
}
